package com.unknow.first.dapp.admin.account.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.unknow.first.dapp.admin.account.constants.FlashSwapConstants.PairStatus;
import com.unknow.first.dapp.admin.account.dto.FlashSwapPairQueryDTO;
import com.unknow.first.dapp.admin.account.mapper.FlashSwapPair;
import com.unknow.first.dapp.admin.account.service.FlashSwapPairService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.cloud.annotation.SystemResource;
import org.cloud.constant.CoreConstant.AuthMethod;
import org.cloud.utils.MyBatisPlusUtil;
import org.cloud.vo.CommonApiResult;
import org.common.CommonPage;
import org.common.CommonParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/flash/swap/pair/app")
@Api(value = "APP:闪兑交易队API", tags = "APP:闪兑交易队API")
@SystemResource(path = "/flash/swap/pair/app")
public class FlashSwapPairController {

    @Autowired
    FlashSwapPairService flashSwapPairService;

    @GetMapping
    @ApiOperation("查询闪兑交易队")
    @SystemResource(value = "/list", description = "查询闪兑交易队", authMethod = AuthMethod.ALLSYSTEMUSER)
    public CommonApiResult<CommonPage<FlashSwapPair>> getFLashSwapPair(FlashSwapPairQueryDTO queryDTO, CommonParam commonParam) {
        QueryWrapper<FlashSwapPair> queryWrapper = MyBatisPlusUtil.single().getPredicate(queryDTO);
        queryWrapper.eq("status", PairStatus.ACTIVE.value);
        PageHelper.startPage(commonParam.getPage(), commonParam.getLimit(), commonParam.getSorts());
        return CommonApiResult.createSuccessResult(CommonPage.restPage(flashSwapPairService.list(queryWrapper)));
    }

}
